<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>找到数组中出现最频繁的偶数</title>
</head>

<body>
  <script>
    function arr(nums) {
      let obj = {}
      let max = -1
      for (let i in nums) {
        obj[nums[i]] = obj[nums[i]] ?? 0
        obj[nums[i]]++
        let a = nums[i]
        if (a % 2 == 0 && (max == -1 || (obj[a] > obj[max] || (obj[a] == obj[max] && max > a)))) {
          max = nums[i]
        }
      }
      return max
    };
    console.log(arr([0, 1, 2, 2, 4, 4, 1]));
  </script>
</body>

</html>